//
//  CEOPeiTaoVC.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/17.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "CEOPeiTaoVC.h"

#import "CeoBusCell.h"
#import "TodoHttpManager.h"
#import "CeoPeiTaoXVC.h"
@interface CEOPeiTaoVC ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)UITableView *tabView;
@property(nonatomic,strong)NSMutableArray *shenArr;
@end

@implementation CEOPeiTaoVC

-(void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didTDCeoMePeiSPLB:) name:TDCeoMePeiSPLB object:nil];
    
    [_manager userCeoPeiShenPLB];
    
}

-(void)didTDCeoMePeiSPLB:(NSNotification *)notifo
{
    if (notifo.object !=0)
    {
        _shenArr = [notifo.object objectForKey:@"data"];
        [_tabView reloadData];
    }
}
-(void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:TDCeoMePeiSPLB object:nil];
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    _manager = [TodoHttpManager sharedManager];
    _tabView = [[UITableView alloc] initWithFrame:CGRectMake(0, 41, B_WIDTH, B_HEIGHT-00) style:UITableViewStylePlain];
    _tabView.delegate = self;
    _tabView.dataSource = self;
    _tabView.rowHeight = 40;
    _tabView.backgroundColor = BgColor;
    _tabView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:_tabView];
    [self setUIBusHeader];

    
}

-(void)setUIBusHeader
{
    UIView *aVi = [[UIView alloc] initWithFrame:CGRectMake(0, 0, B_WIDTH, 40)];
    aVi.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:aVi];
    NSArray *titArr = @[@"报批日期",@"期数",@"楼号",@"物业类型",@"审批状态"];
    UILabel * tempView = [[UILabel alloc]init];
    NSInteger count = 4;//设置一排view的个数
    NSInteger margin = 10;//设置相隔距离
    NSInteger height = 20;//设置view的高度
    for (int i = 0; i < count; i ++) {
 
        UILabel *lab = [[UILabel alloc] init];
        lab.textColor = [UIColor orangeColor];
        lab.font = [UIFont systemFontOfSize:12];
        lab.textAlignment = NSTextAlignmentCenter;
        lab.text = titArr[i];
        [aVi addSubview:lab];
        
        
        //[aVi addSubview:view];
        if (i == 0) {
            [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(aVi).offset(margin);
                make.centerY.equalTo(aVi);
                make.height.mas_equalTo(height);
            }];
        }
        else if (i == count -1){
            [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.right.equalTo(aVi).offset(-margin);
                make.left.equalTo(tempView.mas_right).offset(margin);
                make.centerY.equalTo(tempView);
                make.height.equalTo(tempView);
                make.width.equalTo(tempView);
            }];
        }
        else{
            [lab mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(tempView.mas_right).offset(margin);
                make.centerY.equalTo(tempView);
                make.height.equalTo(tempView);
                make.width.equalTo(tempView);
            }];
        }
        tempView = lab;
        [lab layoutIfNeeded];
    }
    
    
    
    
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _shenArr.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static  NSString *ID = @"Cell";
    CeoBusCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell)
    {
        cell = [[CeoBusCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    
    if ([cell isKindOfClass:[CeoBusCell class]])
    {
        if (_shenArr.count !=0)
        {
            NSDictionary *dict = [_shenArr objectAtIndex:indexPath.row];
            [(CeoBusCell *)cell setBusCellWithDateLab:dict[@"paopi_date"] withQishu:dict[@"qishu"] withWuType:dict[@"wylx"] withStatue:dict[@"status"] withShenStr:dict[@"shenpi_status"]];
        }
        
    }

    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    
    
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CeoPeiTaoXVC *busXVC = [[CeoPeiTaoXVC alloc] init];
    busXVC.piID = [[_shenArr objectAtIndex:indexPath.row] objectForKey:@"id"];
    busXVC.titleStr = [[_shenArr objectAtIndex:indexPath.row] objectForKey:@"wylx"];
    busXVC.peiTypeID = [[_shenArr objectAtIndex:indexPath.row] objectForKey:@"shenpi_status"];
    [self.navigationController pushViewController:busXVC animated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
